/*
 * Team Name: Team Sasquatch
 * Cody Sharff
 * Anthony Rios
 * Prince Kishore
 * Travis Drake
 */

package model;

import java.util.HashMap;
import java.util.Map;

/**
 * This class represents an item that contains
 * information about the item such as ID, name,
 * quantity, minimum starting bid, donor, size,
 * and storage.
 * 
 * @author Anthony Rios
 * @author Modified by Travis Drake to replace double representation of money with integer representation.
 */
public class Item {
	
	public static int next_item_id = 1;

	/**
     * Static method that returns the next item id.
     */
    public static int getNext_item_id()
    {
        return next_item_id;
    }

    /**
     * Static method that sets the next item ID.
     */
    public static void setNextItemID(int next_item_id)
    {
        Item.next_item_id = next_item_id;
    }

    /** 
     * The item ID.
     */
	private final int my_item_id;
	
	/**
	 * The name of this item.
	 */
	private String my_item_name;
	
	/**
	 * The quantity of this item up for auction. (bundle for one sale)
	 */
	private int my_quantity;
	
	/**
	 * The starting bid for this item.
	 */
	private int my_min_start_bid;
	
	/**
	 * The name of the person donating this item up for auction.
	 */
	private String my_donor;
	
	/** 
	 *  The size of this item.
	 */
	private int my_size;
    
    /**
     * Where this item is being stored.
     */
    private String my_storage;
    
    /**
     * A description of this item, if necessary.
     */
    private String my_comment;
	
    /**
     * Condition of the item, defined by an
     * enumeration.
     */
	private Condition my_condition;
	
	/** 
	 * The bids placed on the item.
	 */
	private final Map<String, Integer> bids = new HashMap<String, Integer>();
	
	/**
	 * Constructs a new item object.
	 */
	public Item(final int the_item_id, final String the_item_name, 
			final int the_quantity, final int the_min_start_bid, 
			final String the_donor, final int the_size,
			final String the_storage, final Condition the_condition, final String the_comment) {
		my_item_id = the_item_id;
		my_item_name = the_item_name;
		my_quantity = the_quantity;
		my_min_start_bid = the_min_start_bid;
		my_donor = the_donor;
		my_size = the_size;
		my_storage = the_storage;
		my_condition = the_condition;
		my_comment = the_comment;
	}

	/**
	 * Add_bid adds a bid to the item.
	 *
	 * @param the_user_id the id of the user to store as a key to get the bid.
	 * 
	 * @requires the_user_id != null
	 * @requires the_bid > 0.00
	 * @ensures result == ErrorType.NO_ERROR || result == ErrorType.MORE_THAN_ONE_BID_PER_ITEM 
	 * 										 || ErrorType.BID_BELOW_MINIMUM
	 */
	public ErrorType addBid(final String the_user_id, final int the_bid) {
		ErrorType result = ErrorType.NO_ERROR;
		if (bids.containsKey(the_user_id)) {
			result = ErrorType.MORE_THAN_ONE_BID_PER_ITEM;
		} else if (the_bid < getMinStartingBid()) {
			result = ErrorType.BID_BELOW_MINIMUM;
		} else {
			bids.put(the_user_id, the_bid);
		}
		return result;
	}
	
	/**
	 * Get a placed bid.
	 * 
	 * @param my_user_id the if of the user to place the bid.
	 * 
	 * @return result, if it contains -1 the user has not placed a bid else the
	 * placed bid is returned.
	 */
	public int getAPlacedBid(final String my_user_id) {
		int result = -1;
		if (bids.containsKey(my_user_id)) {
			result = bids.get(my_user_id);
		}
		return result;
	}
	
	/**
	 * Returns the map that contains bids placed on the item.
	 */
	public Map<String, Integer> getBids() {
        return bids;
	}
	
	/**
	 * Returns the items id.
	 */
	public int getItemID() {
		return my_item_id;
	}
	
	/**
	 * Returns the items name.
	 */
	public String getItemName() {
		return my_item_name;
	}
	
	/**
	 * Returns the quantity of the item.
	 */
	public int getQuantity() {
		return my_quantity;
	}
	
	/**
	 * Returns the minimum starting bid required
	 * of the item.
	 */
	public int getMinStartingBid() {
		return my_min_start_bid;
	}

	/**
	 * Returns the items donor.
	 */
	public String getDonor() {
		return my_donor;
	}

	/**
	 * Returns the size of the item.
	 */
	public int getSize() {
		return my_size;
	}

	/**
	 * Returns the items storage location.
	 */
    public String getStorage() {
        return my_storage;
    }

    /**
     * Returns any comments made about the item.
     */
    public String getComment() {
        return my_comment;
    }
	
    /**
     * Returns the items condition.
     */
	public Condition getCondition() {
		return my_condition;
	}
	
	/**
	 * Sets the item name.
	 */
	public void setItemName(String the_new_item_name) {
		my_item_name = the_new_item_name;
	}
	
	/**
	 * Sets the items quantity.
	 */
	public void setQuantity(int the_new_quantity) {
		my_quantity = the_new_quantity;
	}

	/**
	 * Sets the minimum starting bid for the item..
	 */
	public void setMinStartingBid(int the_new_starting_bid) {
		my_min_start_bid = the_new_starting_bid;
	}

	/**
	 * Sets the items donor.
	 */
	public void setDonor(String the_new_donor) {
		my_donor = the_new_donor;
	}
	
	/**
	 * Sets the item size.
	 */
	public void setSize(int the_new_size) {
		my_size = the_new_size;
		
	}

	/**
	 * Sets the item storage.
	 */
	public void setStorage(String the_new_storage) {
		my_storage = the_new_storage;
	}
	
	/**
	 * Sets the condition this item is in.
	 *
	 */
	public void setCondition(Condition the_new_condition) {
		my_condition = the_new_condition;
	}

	/**
	 * Returns a String representation of the item.
	 *
	 *@return a String including the item name,price, and if the item is bulk 
	 *            it prints the items bulk price and quantity needed to get bulk price.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append(my_item_name);
		return sb.toString();
	}
}
